package com.EVO.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class BmiServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("name");
        String height = request.getParameter("h");
        String weight = request.getParameter("w");

        float h = Float.valueOf(height);
        float w = Float.valueOf(weight);
        float bmi = w/(h*h);
        String msg = "";
        if(bmi <= 18.5){
            msg = "偏瘦";
        }else if(bmi > 18.5 && bmi <= 23.9){
            msg = "体重正常";
        }else if(bmi > 24 && bmi <= 27){
            msg = "偏胖";
        }else{
            msg = "严重肥胖";
        }

        msg = "你好: "+name+"你的BMI值是: "+bmi+","+msg;

        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print(msg);
    }
}
